package com.web.hawaste.mapper;

import com.web.hawaste.entity.SysUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author Suzy
 * @since 2022-09-26
 */
public interface SysUserMapper extends BaseMapper<SysUser> {
    /**
     * 方法名: selectByRid
     * 描述: 根据角色Id查询用户信息
     *
     * @param rid
     * @return java.util.List<com.web.hawaste.entity.SysUser>
     * @date 2022/10/11 20:27
     * @auther YangSuzy
     **/
    @Select("SELECT su.* FROM sys_user_role sur,sys_user su\n" +
            "WHERE\n" +
            "sur.del_flag=0\n" +
            "AND\n" +
            "su.del_flag=0\n" +
            "AND\n" +
            "sur.role_id= #{rid} \n" +
            "AND\n" +
            "sur.user_id=su.id")
    List<SysUser> selectByRid(long rid);

    @Select("SELECT\n" +
            "\t* \n" +
            "FROM\n" +
            "\tsys_user \n" +
            "WHERE\n" +
            "\toffice_id = #{oid} \n" +
            "\tAND id NOT IN (\n" +
            "SELECT\n" +
            "\tsu.id \n" +
            "FROM\n" +
            "\tsys_user_role sur,\n" +
            "\tsys_user su \n" +
            "WHERE\n" +
            "\tsur.del_flag = 0 \n" +
            "\tAND su.del_flag = 0 \n" +
            "\tAND sur.role_id = #{rid} \n" +
            "\tAND sur.user_id = su.id \n" +
            "\t)")
    List<SysUser> selectNoRole(@Param("rid") long rid, @Param("oid") long oid);


}
